#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
    void paintEvent(QPaintEvent *event);
    void initsnake();
    void keyPressEvent(QKeyEvent *event);
     QRect createfood();//产生食物
     void iseat();
     void ishit();
private slots:
    void snakeupdate();

private:
    Ui::Widget *ui;
    //QRect vsnakeRect;
    QTimer *timer;//定时器
    char ndirection;//方向
    bool blsrun;//是否开始
    bool blsover;//是否结束
    QVector<QRect> vsnakeRect;//蛇
    QRect snakehead;//蛇头
    QString display;
    QRect food;//食物
    int score;//得分
    int speed;

};
#endif // WIDGET_H
